package com.woniu.atms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.atms.entity.G5Passenger;
import com.woniu.atms.entity.G5Ticket;
import com.woniu.atms.mapper.G5PassengerDao;
import com.woniu.atms.mapper.G5TicketDao;
import com.woniu.atms.service.G5TicketService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (G5Ticket)表服务实现类
 *
 * @author makejava
 * @since 2022-01-19 11:11:18
 */
@Service("g5TicketService")
public class G5TicketServiceImpl extends ServiceImpl<G5TicketDao, G5Ticket> implements G5TicketService {
    @Resource
    private G5TicketDao g5TicketDao;

    /**
     * 根据订单号查询车票
     *
     * @param orderId
     * @return
     */
    @Override
    public List<G5Ticket> queryByOrderId(Integer orderId) {
        return g5TicketDao.queryByOrderId(orderId);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public G5Ticket queryById(Integer id) {
        return this.g5TicketDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param g5Ticket    筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<G5Ticket> queryByPage(G5Ticket g5Ticket, PageRequest pageRequest) {
        long total = this.g5TicketDao.count(g5Ticket);
        return new PageImpl<>(this.g5TicketDao.queryAllByLimit(g5Ticket, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param g5Ticket 实例对象
     * @return 实例对象
     */
    @Override
    public G5Ticket insert(G5Ticket g5Ticket) {
        this.g5TicketDao.insert(g5Ticket);
        return g5Ticket;
    }

    /**
     * 修改数据
     *
     * @param g5Ticket 实例对象
     * @return 实例对象
     */
    @Override
    public G5Ticket update(G5Ticket g5Ticket) {
        this.g5TicketDao.update(g5Ticket);
        return this.queryById(g5Ticket.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.g5TicketDao.deleteById(id) > 0;
    }
}
